package com.leyou.web;

import com.leyou.dto.CategoryDTO;
import com.leyou.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }
    /*
    * todo
    *   根据分类的父id查询对应的子的集合
    *
    * */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>listCategoryByPid(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(this.categoryService.listCategoryByPid(pid));
    }

    /**todo
     *    根据id查询分类
     *    @param id 分类id
     *    @return 分类对象
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id") Long id){
        return ResponseEntity.ok(this.categoryService.queryCategoryById(id));
    }

    /*
    * todo 根据id集合查询对应的分类对象集合
    * */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>>listCategoryByIds(@RequestParam("ids") List<Long>ids){
        return ResponseEntity.ok(this.categoryService.listCategoryByIds(ids));
    }


    /*
    * todo
    *  根据品牌id，查询对应的分类集合
    * */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> listCategoryByBrand(@RequestParam("id") Long bid){
        return ResponseEntity.ok(this.categoryService.listCategoryByBrand(bid));
    }


}
